package Controller;

import java.io.Serializable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import Entity.Product;
import Communication.Client;

import Entity.Type;
import Entity.Category;
import Controller.NewProductToCatalogController.NewProductToCatalogListener;
import View.LoginView;
import View.NewProductToCatalogView;
import HandleDB.ProductQuery;
import HandleDB.CustomerQuery;


public class NewProductToCatalogController implements Serializable {
	private static final long serialVersionUID = 1L;
	NewProductToCatalogView ProductView;
	Client client;
	ProductQuery productModel;
	
	public NewProductToCatalogController (Client client, WorkerMainMenuController workerMainMenuController) {
		this.client = client;
		ProductView = new NewProductToCatalogView();
		//productModel= new ProductQuery(client);
		
		ProductView.showWindow();
		
	

		ProductView.addNewProductToCatalogListener(new NewProductToCatalogListener(workerMainMenuController));
	}
	
	
	
	class NewProductToCatalogListener implements ActionListener
	{
		WorkerMainMenuController workerMainMenuController;
		
		public  NewProductToCatalogListener(WorkerMainMenuController workerMainMenuController){
			this.workerMainMenuController = workerMainMenuController;
			productModel = new ProductQuery(client);
		}
	

	public void actionPerformed(ActionEvent event) {
		
		
		if (event.getSource() == ProductView.getSubmitButton())
		{
			if (productModel.isEmpty(ProductView.getProductID()) || productModel.isEmpty(ProductView.getProductName()) ||
					productModel.isEmpty(ProductView.getProductPrice()) || productModel.isEmpty(ProductView.getProductDescription()) ||
					productModel.isEmptyBool(ProductView.getProductPicture()) )
				SystemController.displayErrorMessage("One or more fields are Empty");
			
			else
			{ 
				SystemController.displayMessage("Product Added successfully !");
				ProductView.showWindow();
				workerMainMenuController.hideWindow();
				ProductView.clearFields();
				
			}
		}
		else if (event.getSource() == ProductView.getBackBtn())
		{
			workerMainMenuController.showWindow();
			ProductView.hideWindow();
			ProductView.clearFields();
		}
		
		
	}	
	}
}


